package com.chensf.studydemo.guide.design

import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import androidx.viewpager.widget.PagerAdapter
import com.chensf.studydemo.R
import com.google.android.material.appbar.AppBarLayout
import kotlinx.android.synthetic.main.activity_pull_refresh_demo.*
import kotlinx.android.synthetic.main.activity_pull_refresh_demo2.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

class PullRefreshDemo2 : AppCompatActivity(){

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_pull_refresh_demo2)
        val list = mutableListOf<TextView>()
        for(index in 1..10){
            val view = layoutInflater.inflate(R.layout.view_pager_item,null) as TextView
            view.text = "测试页面-$index"
            list.add(view)
        }

        viewPager.adapter = object :PagerAdapter(){
            override fun getCount(): Int {
                return 10
            }

            override fun isViewFromObject(view: View, obj: Any): Boolean {
                return view == obj
            }

            override fun instantiateItem(container: ViewGroup, position: Int): Any {
                container.addView(list[position])
                return list[position]
            }

            override fun destroyItem(container: ViewGroup, position: Int, obj: Any) {
                container.removeView(obj as View)
            }
        }
    }
}